import cv2 as cv
import matplotlib.pyplot as plt
import custom

def exchange(image):
	image = cv.cvtColor(image, cv.COLOR_BGR2GRAY)

	for row in range(0,image.shape[0]):
		for col in range(0,image.shape[1]):
			m=image[row][col]/255.00
			if m<=0.2700:
				image[row][col]=0
			elif m>0.2700 and m<=0.5000:
				image[row][col]=(m-0.27)/0.23*127
			elif m>0.5000 and m<=0.7200:
				image[row][col]=(m-0.5)/0.22*255+(0.72-m)/0.22*127
			else:
				image[row][col]=255

	custom.showPicture('dst',image)


	# cv.imshow('dst',image)




src= cv.imread('pic/test.png')
gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
custom.showPicture("gray",gray)
exchange(src)
cv.waitKey(0)
